﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public class Alert
{
    public static void Show(string message) 
    {
       // Cleans the message to allow single quotation marks 
       string cleanMessage = message.Replace("'", "\'"); 
       string script = "<script type='text/javascript'>alert('" + cleanMessage + "');</script>"; 

       // Gets the executing web page 
       Page page = HttpContext.Current.CurrentHandler as Page; 

       // Checks if the handler is a Page and that the script isn't allready on the Page 
       if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert")) 
       { 
         page.ClientScript.RegisterClientScriptBlock(typeof(Alert), "alert", script);
       }
    }
    public static void Load_DropDownList(DropDownList ddl, DataTable dt, string HienThi, string GiaTri ,string BatDau)
    {
        try
        {
            if (dt != null && dt.Rows.Count > 0)
            {
                ddl.DataSource = dt;
                ddl.DataValueField = GiaTri;
                ddl.DataTextField = HienThi;
                ddl.DataBind();                
            }
            ListItem itemRoot = new ListItem();
            itemRoot.Text = BatDau;
            itemRoot.Value = "0";
            ddl.Items.Insert(0, itemRoot);
            dt = null;
        }
        catch (Exception ex)
        {

        }
    }
    public static string taochuoi(int PasswordLength)
    {
        string _allowedChars = "abcdefghijkmnopqrstuvwxyz0123456789";
        Random randNum = new Random();
        char[] chars = new char[PasswordLength];
        int allowedCharCount = _allowedChars.Length;

        for (int i = 0; i < PasswordLength; i++)
        {
            chars[i] = _allowedChars[(int)((_allowedChars.Length) * randNum.NextDouble())];
        }
        return new string(chars);
    }

}

